package org.leon.controller;

import org.leon.pojo.Comment;
import org.leon.pojo.QueryEntity;
import org.leon.service.CommentService;
import org.leon.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;


@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private CommentService service;

    @RequestMapping("/hello")
    public String hello() {
        return "Hello World";
    }

    @PostMapping("/upload")
    @ResponseBody
    public String upload(@RequestParam("file") MultipartFile file, QueryEntity queryEntity) {
        if (file.isEmpty()) {
            return "上传失败，请选择文件";
        }

        String fileName = file.getOriginalFilename();

        return "文件名称：" + fileName;
    }

    @RequestMapping("/comment/id")
    public Comment findById(Integer id) {
        return service.findCommentById(id);
    }

}
